/****************************************************************************
*created by yang.zheng on 2020-08-11 for ajax entry file
****************************************************************************/

//引入axios对象
import axios from 'axios'


/**
 * 定义一个ajax配置方法
 * @param {AxiosRequestConfig} request   需要传递的参数
 */
const Ajax = async request => {
    let param = {
        baseURL : '/apis',
        url : request.url,
        params : request.params || {},
        data : request.data || {},
        method : request.method ? request.method : 'GET',
        header : {'Content-type' : 'application/json;charset=utf-8'},
        timeout : 5000
    };

    //判断是否有上传进度的回调参数
    if (request.onUploadProgress) {
        param.onUploadProgress = request.onUploadProgress;
    }

    let res = await axios(param).catch(e => {
        console.log(e)
        return {code : 600, message : 'local error'};
    });
    if (res) return res.data;
}

//导出ajax方法
export default Ajax;